import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import router from './router';
import store from './store';

import "./api/mock"
import Cookie from 'js-cookie'

Vue.config.productionTip = false

Vue.use(ElementUI);
// elementUI 按需引入
// Vue.use(Button)

// 添加全局前置导航守卫
router.beforeEach((to, from, next)=>{
  const token = Cookie.get('token')
  // 判断 token 是否存在

  if(!token && to.name !== 'login'){
    next({name: 'login'})
  } else if(token && to.name === 'login'){
    next({name: 'home'})
    console.log('1111')
  } else {
    next()
  }
})

new Vue({
  router,  // 挂载实例
  store,
  
  render: h => h(App),
}).$mount('#app')
